package labox.innovation.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import labox.innovation.config.Config.IdFactoryType;
import labox.innovation.config.Config.ObjectMapType;
import labox.innovation.config.Config.ObjectSetType;
import labox.innovation.util.L2Properties;

public class IdfactoryConfig {
    private static final Logger _log = LoggerFactory.getLogger(IdfactoryConfig.class.getName());
    private static final String ID_CONFIG_FILE = "./config/idfactory.properties";

    public static ObjectMapType MAP_TYPE;

    public static ObjectSetType SET_TYPE;

    public static IdFactoryType IDFACTORY_TYPE;

    public static boolean BAD_ID_CHECKING;

    public static void load() {
        _log.info("Loading idfactory Configuration Files...", Config.SERVER_ID);
        InputStream is = null;
        try {
            L2Properties idSettings = new L2Properties();
            is = new FileInputStream(new File(ID_CONFIG_FILE));
            idSettings.load(is);

            MAP_TYPE = ObjectMapType.valueOf(idSettings.getProperty("L2Map", "WorldObjectMap"));
            SET_TYPE = ObjectSetType.valueOf(idSettings.getProperty("L2Set", "WorldObjectSet"));
            IDFACTORY_TYPE = IdFactoryType.valueOf(idSettings.getProperty("IDFactory", "GUID"));
            BAD_ID_CHECKING = Boolean.parseBoolean(idSettings.getProperty("BadIdChecking", "True"));
        } catch (Exception e) {
            _log.error("Failed to Load " + ID_CONFIG_FILE + " File.", e);
        } finally {
            try {
                is.close();
            } catch (IOException e) {
                _log.error("InputStream close occured IOException");
            }
        }
    }
}
